package spider.web;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.IOException;

/**
 * @author: zhangzeli
 * @date 15:04 2018/5/4
 * <P></P>
 */
public class Spider1 {

    public void Test() throws IOException {
        GetMethod getMethod = new GetMethod("https://hm.baidu.com/hm.js?2ea5d7a3a13a1da3236117fd8ee2b071");
        HttpClient httpClient = new HttpClient();
        int i = httpClient.executeMethod(getMethod);
        System.out.println("======="+i);
        System.out.println("response="+getMethod.getResponseBodyAsString());
        getMethod.releaseConnection();
    }

    public void testPost() throws IOException {
        PostMethod postMethod = new PostMethod("http://www.saybot.com");
        GetMethod getMethod = new GetMethod("http://www.saybot.com");
        NameValuePair[] postData = new NameValuePair[2];
        postData[0]=new NameValuePair("武器","枪");
        postData[1]=new NameValuePair("什么武器","神枪");
        HttpClient httpClient = new HttpClient();
        int i = httpClient.executeMethod(getMethod);
        System.out.println("======="+i);
        System.out.println("response="+getMethod.getResponseBodyAsString());
        getMethod.releaseConnection();
    }
}
